<?php
namespace app\home\controller;

use think\Controller;
use think\Session;
use think\Request;
use app\home\model\GoodsModel;

class Goods extends Controller
{
	/**
	*	商品分类页面
	*/
	public function category()
	{

		$GoodsModel = new GoodsModel();
		/*商品分类-顶级分类*/
		$category = $GoodsModel->getParCate();
		$this->assign('category',$category);
		return $this->fetch();
	}

	/**
	*	商品分类-子类
	*/
	public function indexCategory()
	{
		$data = $this->request->param();
		$GoodsModel = new GoodsModel();
		$list = $GoodsModel->getCategory($data['id']);

		if($list){
			return returnJson($code=0,$msg='获取成功',$list);
		}else{
			return returnJson($code=1,$msg='获取失败',$list);
		}
	}

	/**
	*	商品分类对应的商品列表
	*/
	public function goods()
	{
		$data = $this->request->param();
		$GoodsModel = new GoodsModel();
		$catename = $GoodsModel->getCategoryName($data['id']);
		$this->assign('catename',$catename);
		return $this->fetch();
	}

	/**
	*	商品分类对应的商品
	*/
	public function goodsIndex()
	{
		$data = $this->request->param();
		$GoodsModel = new GoodsModel();
		$list = $GoodsModel->getGoods($data['id']);
		if($list){
			return returnJson($code=0,$msg='获取成功',$list);
		}else{
			return returnJson($code=1,$msg='获取失败',$list);
		}
	}

	/**
	*	团购商品-详情页
	*/
	public function gbulkDetail()
	{
		$data = $this->request->param();
		$GoodsModel = new GoodsModel();
		$goods = $GoodsModel->getGoodsDetail($data['id']);
		/* 商品id */
		$this->assign('list',$data);
		$this->assign('goods',$goods);
		return $this->fetch();
	}

	/**
	*	普通商品-详情页
	*/
	public function goodsDetail()
	{
		$data = $this->request->param();
		$GoodsModel = new GoodsModel();
		$goods = $GoodsModel->getGoodsDetail($data['id']);
		/* 商品id */
		$this->assign('list',$data);
		$this->assign('goods',$goods);
		return $this->fetch();
	}

	/**
	*	商品详情页
	*/
	public function productDetail()
	{
		$data = $this->request->param();
		$GoodsModel = new GoodsModel();
		$list = $GoodsModel->getGoodsDetail($data['id']);
		if($list){
			return returnJson($code=0,$msg='获取成功',$list);
		}else{
			return returnJson($code=1,$msg='获取失败',$list);
		}
	}

	/**
	*	获取某个商品对应的规格信息
	*/
	public function goodsInfo()
	{
		/* 商品id */
		$data = $this->request->param();
		$GoodsModel = new GoodsModel();
		$list = $GoodsModel->goodsInfo($data['id']);
		if($list){
			return returnJson($code=0,$msg='获取成功',$list);
		}else{
			return returnJson($code=1,$msg='获取失败',$list);
		}
	}

	/**
	*	点击加入购物车弹窗
	*/
	public function getClickCart()
	{
		/* 商品id */
		$data = $this->request->param();
		$GoodsModel = new GoodsModel();
		$list = $GoodsModel->getClickCart($data['id']);
		if($list){
			return returnJson($code=0,$msg='获取成功',$list);
		}else{
			return returnJson($code=1,$msg='获取失败',$list);
		}
	}

}